package com.caiden_micheal.user.mapper;

import com.caiden_micheal.permission.domain.Permission;
import com.caiden_micheal.position.domain.Position;
import com.caiden_micheal.user.domain.PositionAuthority;
import com.caiden_micheal.user.domain.UserAuthority;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface PositionAuthorityMapper {
    List<UserAuthority> findBatchAuthorityIdByPositionIds(@Param("ids") List<Long> ids);

    void updatePositionName(@Param("position") Position position);

    @Delete("DELETE FROM sys_position_authority WHERE position_id=#{positionId}")
    void removeByPositionId(@Param("positionId") Long positionId);

    @Select("SELECT authority_id FROM sys_position_authority WHERE position_id=#{positionId}")
    List<Long> findAuthorityIdsByPositionId(@Param("positionId") Long positionId);

    @Select("SELECT position_id FROM sys_position_authority WHERE authority_id=#{authorityId}")
    List<Long> findPositionIdsByAuthorityId(@Param("authorityId") Long authorityId);

    void add(@Param("positionAuthority") PositionAuthority positionAuthority);

    void batchAdd(@Param("positionList") List<Position> positionList, @Param("permission") Permission permission);

    @Delete("DELETE FROM sys_position_authority WHERE position_id=#{positionId} AND authority_id=#{authorityId}")
    void removeByPositionIdAndAuthorityId(@Param("positionId") Long positionId, @Param("authorityId") Long authorityId);

    void batchAddByAuthorityListAndPosition(@Param("permissionList") List<Permission> permissionList, @Param("position") Position position);

    List<Long> findAuthorityIdsByOrgIds(@Param("positionIdList") List<Long> positionIdList);

    @Delete("DELETE FROM sys_position_authority WHERE authority_id=#{permissionId}")
    void removeByPermissionId(@Param("permissionId") Long permissionId);
}
